<?php
namespace Home\Controller;
class IndexController extends BaseController {
    public function index(){
        $endtime = date("Ymd", strtotime('+30day'));
        $starttime = date('Ymd');
        $xml = getUsers($this->userinfo['orgseq'], "", $endtime, $starttime, "", "", "");
        $count       = count($xml);  // 统计数组元素个数
        $Page        = new \Think\Page($count,C('PAGE_LIST'));// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $Page->setConfig("prev", "上一页");
        $Page->setConfig("next", "下一页");
        $Page->setConfig("theme", "%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");
        $pagexml = array_slice($xml, $Page->firstRow, $Page->listRows);
        $this->signat = $this->signatures;
        $this->page  = $Page->show();// 分页显示输出
        $this->users = $pagexml;
        $this->display();
    }
    
    public function postMsg() {
        $msgcontent = I('post.msgcontent')."【".I('post.sign')."】";
        $phones = array_filter(I('post.phones'));
        $mobiles = implode(',', $phones);
        empty($msgcontent) || empty($phones) && $this->error('操作非法，请填写短信内容或选择接收短信的用户',U('Index/index'));
        //发送短信
        $res = sendSMS($this->userinfo['msgname'], $this->userinfo['msgpass'], $mobiles, $msgcontent, $this->userinfo['msgapikey']);
        //进行记录
        $data['msgcontent'] = $msgcontent;
        $data['mobiles']    = $mobiles;
        $data['status']     = $res;
        $data['uid']        = $this->userinfo['id'];
        $data['logtime']    = time();
        $res = D('Log')->addLog($data);
        if ($res) {
            $this->success('短信发送成功',U('Index/index'));
        }
    }
}